﻿//------------------------------------------------------------------------------ 
// <copyright file="JSource.cs" company="Fm Computer">
//     Copyright (c) Fm Computer di Menatti Fulvia.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------------
namespace FmjQuery
{
    using System.ComponentModel;
    using System.Web.UI;

    /// <summary>
    /// WebResource for jQuery control
    /// </summary>
    public class JSource
    {
        #region Costruct
        /// <summary>
        /// Initializes a new instance of the JSource class. Create new resource without value
        /// </summary>
        public JSource()
        {
            this.IsWebResource = false;
        }

        /// <summary>
        /// Initializes a new instance of the JSource class. Create new resource without value
        /// </summary>
        /// <param name="name">name of resouce</param>
        /// <param name="url">url of resource</param>
        /// <param name="type">type of resource</param>
        public JSource(string name, string url, JSourceType type)
            : this(name, url, type, false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the JSource class. Create new resource without value
        /// </summary>
        /// <param name="name">name of resouce</param>
        /// <param name="url">url of resource</param>
        /// <param name="type">type of resource</param>
        /// <param name="isWebResource">indicates if is embedded resource</param>
        public JSource(string name, string url, JSourceType type, bool isWebResource)
        {
            this.Name = name;
            this.Url = url;
            this.Type = type;
            this.IsWebResource = isWebResource;
        }
        #endregion

        #region Property
        /// <summary>
        /// Gets or sets name of resource
        /// </summary>
        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets url of resource
        /// </summary>
        [UrlProperty]
        public string Url
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets type of resource
        /// </summary>
        public JSourceType Type
        {
            get;
            set;
        }

        /// <summary>
        /// Gets a value indicating whether resource is embedded
        /// </summary>
        [DefaultValue(false)]
        internal bool IsWebResource
        {
            get; 
            private set;
        }
        #endregion

        #region Override

        /// <summary>
        /// Equals source with other object
        /// </summary>
        /// <param name="obj">object that check if equals</param>
        /// <returns>indicates if object is equals</returns>
        public override bool Equals(object obj)
        {
            JSource eq = obj as JSource;

            if (eq == null)
            {
                return false;
            }

            return this.Url.Equals(eq.Url) && this.Type.Equals(eq.Type);
        }

        /// <summary>
        /// Get Hash code of object
        /// </summary>
        /// <returns>hash code of object</returns>
        public override int GetHashCode()
        {
            return string.Concat(Url, Type).ToLower().GetHashCode();
        }
        #endregion
    }
}
